//关联类型
trait Iterator {
    type Item; //关联类型
    fn next(&mut self) -> Option<Self::Item>;
}
struct Counter {
    count: u32,
}
//泛型trait，可以多次为某structimpl这个trait
trait Iterator2<T> {
    fn next(&mut self) -> Option<T>;
}
impl Iterator for Counter {
    type Item = u32;
    fn next(&mut self) -> Option<Self::Item> {
        if self.count < 5 {
            self.count += 1;
            Some(self.count)
        } else {
            None
        }
    }
}
//conflicting implementation for `Counter`
//关联类型只能在一个trait中实现一次。
// impl Iterator for Counter {
//     type Item = i32;
//     fn next(&mut self) -> Option<i32> {
//         if self.count < 5 {
//             self.count += 1;
//             Some(self.count as i32)
//         } else {
//             None
//         }
//     }
// }

impl Iterator2<u32> for Counter {
    fn next(&mut self) -> Option<u32> {
        if self.count < 5 {
            self.count += 1;
            Some(self.count)
        } else {
            None
        }
    }
}
impl Iterator2<i32> for Counter {
    fn next(&mut self) -> Option<i32> {
        if self.count < 5 {
            self.count += 1;
            Some(self.count as i32)
        } else {
            None
        }
    }
}
